/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

 /***************************************************************************
  * Name: mp_ini_file.h
  *
  * Purpose: ini file parser implementation for micro player
  *
  * Developer:
  *   wen.gu , 2018-09-03
  *
  * TODO:
  *
  ***************************************************************************/

#ifndef __MF_INI_FILE_H__
#define __MF_INI_FILE_H__

/******************************************************************************
**    INCLUDES
******************************************************************************/
#include <vector>
#include <map>

#include "mp_types.h"

/******************************************************************************
**    MACROS
******************************************************************************/

/**
* if ini file havan't any section,then parser will add a default section
* user cann't use this section name,it is reserve section name.
*/

#define DEFAULT_SECTION_NAME "__default__"

#define LINE_BUF_MAX_LEN   1024 /** the expression line maximum length */

/******************************************************************************
**    TYPE DEFINITIONS
******************************************************************************/
typedef std::string MPIniKey;
typedef std::string MPIniValue;
typedef std::vector<MPIniValue> MPIniValueArray;


typedef std::map<MPIniKey, MPIniValueArray> MPIniSection;

typedef std::map<MPIniKey, MPIniSection> MPIniSectionMap;
    
/******************************************************************************
**    CLASSES/FUNCTIONS DEFINITIONS
******************************************************************************/

class MP_CLASS MPIniFile
{
public:
    MPIniFile();
    virtual ~MPIniFile();
public:
    eMPError load(const std::string& fileName);

    eMPError getValue(const MPIniKey& section, 
                     const MPIniKey& key, 
                     MPIniValue& val);
                           
    eMPError getValues(const MPIniKey& section, 
                      const MPIniKey& key, 
                      MPIniValueArray& vals);

    eMPError getSection(const MPIniKey& key, MPIniSection& ms);

    bool hasSection(const MPIniKey& key);
    bool hasKey(const MPIniKey& section, const MPIniKey& key);

    void dump2Str(std::string& str);
private:

    bool mIsLoaded = false;
    MPIniSectionMap mSections;
    
};


#endif /** !__MF_INI_FILE_H__ */

